/**
 * @program: LeetCode
 * @description: LeetCode :
 * @author: WXY
 * @create: 2022-12-25 16:11
 * @Version 1.0
 **/

public class one2_maxSubArray {
    public static int maxSubArray(int[] nums) {
        int cur = 0;
        int max = Integer.MIN_VALUE;
        int left = 0;
        int right = 0;
        while (right < nums.length) {
            cur += nums[right++];
            max = Math.max(max, cur);
            cur = cur < 0 ? 0 : cur;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] arr = {-2};
        int i = maxSubArray(arr);
        System.out.println(i);
    }

}
